package com.hejian.android.a72ggametools.imageloader;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

/**
 * Created by Administrator on 2016/1/11.
 */
public class MemoryCache implements ImageCache{
    private LruCache<String , Bitmap> lruCache;

    public MemoryCache(){
        int maxMemory = (int) (Runtime.getRuntime().maxMemory()/1024);
        int cacheSize = maxMemory/8;
        lruCache = new LruCache<String,Bitmap>(cacheSize){
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes()*bitmap.getHeight()/1024;
            }
        };
    }


    @Override
    public Bitmap getBitmap(String urlStr) {
        return lruCache.get(urlStr);
    }

    @Override
    public void setImage(String urlStr, Bitmap bitmap) {
        lruCache.put(urlStr,bitmap);
    }

}
